<template>
  <div class="gender">
    <div class="title">
      <p>男女比例</p>
      <img src="../../images/dataScreen-title.png" alt="" />
    </div>

    <div class="sex">
      <div class="man">
        <p class="man-title">男性</p>
        <img src="../../images/man.png" alt="" />
      </div>
      <div class="woman">
        <p class="woman-title">女性</p>
        <img src="../../images/woman.png" alt="" />
      </div>
    </div>
    <div class="rate">
      <p class="man-rate">男士58%</p>
      <p class="woman-rate">女士42%</p>
    </div>
    <div class="charts" ref="charts"></div>
  </div>
</template>

<script setup lang="ts">
import * as echarts from 'echarts'
import { onMounted, ref } from 'vue'

let charts = ref()

onMounted(() => {
  // 初始化echarts实例
  let myCharts = echarts.init(charts.value)
  myCharts.setOption({
    xAxis: {
      show: false,
      min: 0,
      max: 100,
    },
    yAxis: {
      show: false,
      type: 'category',
    },
    series: [
      {
        type: 'bar',
        data: [62],
        barWidth: 20,
        z: 100,
        itemStyle: {
          color: '#007cfe',
          borderRadius: 20,
        },
      },
      {
        type: 'bar',
        data: [100],
        barWidth: 20,
        // 调整女生柱条位置
        barGap: '-100%',
        itemStyle: {
          color: '#fe5979',
          borderRadius: 20,
        },
      },
    ],
    grid: {
      left: 100,
      right: 100,
      bottom: 0,
      top: 0,
    },
  })
})
</script>

<style lang="scss" scoped>
.gender {
  width: 100%;
  height: 100%;
  background: url('../../images/dataScreen-main-lc.png') no-repeat;
  background-size: 100% 100%;
  margin: 20px 0px;
  .title {
    margin-left: 20px;
    p {
      color: white;
      font-size: 20px;
    }
  }

  .sex {
    display: flex;
    justify-content: center;
    margin-top: 30px;
    .man {
      margin: 20px;
      width: 111px;
      height: 115px;
      background: url('../../images/man-bg.png') no-repeat;
      display: flex;
      justify-content: center;
      flex-direction: column;
      align-items: center;

      .man-title {
        margin: -20px 0px 15px 0px;
        color: white;
        font-size: 10px;
      }
    }

    .woman {
      margin: 20px;
      width: 111px;
      height: 115px;
      background: url('../../images/woman-bg.png') no-repeat;
      display: flex;
      justify-content: center;
      align-items: center;
      flex-direction: column;

      .woman-title {
        margin: -20px 0px 15px 0px;
        color: white;
        font-size: 10px;
      }
    }
  }

  .rate {
    display: flex;
    justify-content: space-between;
    color: white;

    .man-rate {
      margin-left: 22%;
    }
    .woman-rate {
      margin-right: 22%;
    }
  }

  .charts {
    height: 130px;
    margin-top: -20px;
  }
}
</style>
